﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;
using System.IO;

public partial class Admin_Phukien : System.Web.UI.Page
{
    PhukienController pPhukienController = new PhukienController();
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            grvPhukien.DataSource = pPhukienController.GetAll();
            grvPhukien.DataBind();
            if(grvPhukien.Rows.Count>0)
            {
                grvPhukien.UseAccessibleHeader = true;
                grvPhukien.HeaderRow.TableSection = TableRowSection.TableHeader;
            }
        }
    }
    [WebMethod]
    public static string deletePhukien(int phukien_id)
    {
        //Select cac hinh anh di kem phu kien
        PhukienController pPhukienController = new PhukienController();
        List<Phukien_Image> list = pPhukienController.getImagePhukien(phukien_id);
        string fileUpload = HttpContext.Current.Server.MapPath("~/");
        foreach (var item in list)
        {
            pPhukienController.deleteImagePhukien(item.Phukien_Image_id);
            
            File.Delete(fileUpload+item.Image);
        }
        if(pPhukienController.Delete(phukien_id)>0)
        {
            return "true";
        }else
        {
            return "false";
        }
    }
}